<template>
	<view>
		<view class="my-1" v-if="list.length>0" v-for="(item,index) in list">
			<f-list-item :title="item.name">
				<image slot="icon" :src="item.avatar?item.avatar:'../../static/demo/1.jpg'" style="width: 80rpx;height: 80rpx;" mode=""></image>
			</f-list-item>
		</view>
		<!-- 默认样式 -->
		<view v-if="list.length===0" class="flex w-100 align-center justify-center text-secondary" style="height: 100rpx;">
			暂无关注
		</view>
		<view v-if="list.length>=10" class="flex align-center justify-center py-3 bg-light">
			<text class="text-muted font">{{loadtext}}</text>
		</view>
	</view>
</template>

<script>
	import fListItem from '@/components/common/f-list-item.vue';
	export default {
		components:{
			fListItem
		},
		data() {
			return {
				list:[],
				loadtext:'上拉加载更多',
				page:1
			}
		},
		onLoad(options) {
			this.getData()
		},
		onPullDownRefresh() {
			this.page=1
			this.getData().then(res=>{
				uni.showToast({
					title:'刷新成功',
					icon:'none'
				})
				uni.stopPullDownRefresh()
			}).catch(err=>{
				uni.showToast({
					title:'刷新失败',
					icon:'none'
				})
				uni.stopPullDownRefresh()
			})
		},
		onReachBottom() {
			if(this.loadtext!=='上拉加载更多'){
				return
			}
			this.page+=1
			this.getData().catch(err=>{
				this.page-=1
				this.loadtext="上拉加载更多"
			})
		},
		methods: {
			getData(){
				this.loadtext='加载中...'
				return this.$H.get(`/user/follows/${this.page}`,{token:true}).then(res=>{
					this.list=this.page===1?res:[...this.list,...res],
					this.loadtext=this.page*10===this.list.length?'上拉加载更多':'没有更多啦'
				})
			}
		}
	}
</script>

<style>

</style>
